package com.zyz.sunliky.controller;

import com.zyz.sunliky.common.ResultCommon;
import com.zyz.sunliky.service.PurchaseService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;


@RequestMapping("/purchase")
@RestController
public class PurchaseController {

    public static final Logger logger = LoggerFactory.getLogger(PurchaseController.class);

    @Autowired
    PurchaseService purchaseService;


    /**
     * 供应商基础信息建立
     * @param supplierCode,productNo
     * @return
     */
    @GetMapping("/price")
    public ResultCommon getSupplier(String supplierCode,String productNo){
        try {

           Map map = purchaseService.getPrice(supplierCode,productNo);

            return new ResultCommon(map,200,"成功");
        }catch (Exception e){
            e.printStackTrace();
            logger.error(e.getMessage());
            return new ResultCommon(null,500,e.getMessage());
        }

    }

    /**采购请求号生成2**/
    @GetMapping("/updateRequestNo2")
    public ResultCommon updateRequestNo2(String fqqhdd){
        try {
            Thread.sleep(1000);
            return new ResultCommon(purchaseService.updateRequestNo2(fqqhdd),200,"ok");
        }catch (Exception e){
            logger.error(e.getMessage());
            return new ResultCommon(null,500,e.getMessage());
        }
    }

    /**非计划物料采购申请生成采购请求**/
    @GetMapping("/createCGQQ")
    public ResultCommon createCGQQ(String userid,String id){
        try {
            return new ResultCommon(null,200,purchaseService.createCGQQ(id));
        }catch (Exception e){
            logger.error(e.getMessage());
            return new ResultCommon(null,500,e.getMessage());
        }
    }

    /**计划/非计划物料采购求-查涂料类型采购记录**/
    @GetMapping("/count")
    public ResultCommon getCount(String cpbh,String type){
        try {
            return new ResultCommon(purchaseService.getCount(cpbh,type),200,"ok");
        }catch (Exception e){
            logger.error(e.getMessage());
            return new ResultCommon(null,500,e.getMessage());
        }
    }


}
